<template>
  <el-header>
    <div class="left-content">
      <!-- 图标的展示 -->
      <el-button size="small" @click="handleCollapse()">
        <el-icon :size="20" :color="color"> <Menu /> </el-icon
      ></el-button>
      <!-- 面包屑 -->
      <el-breadcrumb separator="/" class="bread" style="user-select: none">
        <!-- 首页是一定存在的，所以直接写死 -->
        <el-breadcrumb-item :to="{ path: '/' }"
          ><span>首页</span></el-breadcrumb-item
        >
        <el-breadcrumb-item :to="current.path" v-if="current">
          <span style="user-select: none">{{ current.label }}</span>
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="right-content">
      <el-dropdown>
        <span class="el-dropdown-link">
          <!-- 用户图片 -->
          <img class="user" :src="getImageSrc(4)" />
          <el-icon class="el-icon--right">
            <arrow-down />
          </el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item @click="handleLoginOut">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </el-header>
</template>
<script setup>
import { computed } from 'vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
let store = useStore()
let getImageSrc = (user) => {
  // console.log(import.meta.url)
  // console.log(new URL(`../assets/images/${user}.jpeg`, import.meta.url))
  return new URL(`../assets/images/${user}.jpeg`, import.meta.url).href
}
let handleCollapse = () => {
  store.commit('updateIsCollapse')
}
//计算属性
const current = computed(() => {
  return store.state.currentMenu
})
const router = useRouter()
const handleLoginOut = () => {
  store.commit('cleanMenu')
  router.push({
    name: 'login'
  })
}
</script>
<style lang="less" scoped>
.el-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #333;
}
.right-content {
  // 用户头像
  .user {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}
.left-content {
  display: flex;
  align-items: center;
  .el-button {
    margin-right: 20px;
  }
  p {
    font-size: 16px;
    color: #fff;
  }
  .bread {
    span {
      font-size: 16px;
      color: white;
      :hover {
        color: rgb(100, 158, 170);
        cursor: pointer;
      }
    }
  }
}
</style>
